home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------
- * $Id: rcstime.c,v 1.5 1993/12/02 09:54:59 carlson Exp $
- *
- * rcstime Returns the time of the last RCS update in an RCS file.
- *
- * Synopsis:
- * rcstime [+<format>] [-i] [-R] [-r<rev>] file [[-r<rev>] files...]
- *
- * Description:
- * This program writes to stdout the time of the last update found
- * in the RCS file. The program uses the same search sequence for
- * the RCS file as the standard RCS programs (co, ci, rcs). For
- * information on how it finds the RCS file, see below under File
- * Search Method.
- *
- * The -r<rev> option identifies which revision from the RCS file
- * is to be used in computing the modification time. If just -r
- * is given (with no <rev>), the latest known revision is selected.
- *
- * The +<format> option provides a format that is to be used in
- * writing the time. This format is identical to the date(1)
- * command.
- *
- * The -i option overrides any format provided and prints the date
- * in integer format.
- *
- * The -R option specifies that the actual revision number that was
- * found should also be printed.
- *
- * File Search Method:
- * If the file name ends in ",v", it is take to be an RCS file.
- * All other files are assumed to be working files and the names
- * are converted be RCS files. If no path is provided, the RCS
- * file is looked for in the directory ./RCS and then in the
- * current directory. If a path is provided, the RCS file is
- * looked for only in the directory provided.
- *
- * Revision History:
- * $Log: rcstime.c,v $
- * Revision 1.5 1993/12/02 09:54:59 carlson
- * Found an RCS file that didn't have a comment line. Needed to take out
- * the part where I search for the comment line and modify the loop which
- * looks for revisions to ignore lines until it gets to a revision number.
- *
- * Revision 1.4 93/11/30 15:22:31 carlson
- * Modified to now give the latest time found in the RCS file.
- * Add -R option to provide the revision found.
- *
- * Revision 1.3 92/10/27 10:33:10 carlson
- * Found that I was printing the address and not the time when printing
- * the time in decimal.
- *
- * Revision 1.2 91/07/19 15:15:39 carlson
- * Added Header for RCS.
- * Added -i option for printing time in decimal.
- * Modified to handle new format of cftime using %.
- *
- * Revision 1.1 90/10/09 17:26:51 chris
- * Initial revision
- *
- * 07 Feb 90 Christopher W. Carlson, Silicon Graphics Inc.
- * Initial draft.
- *
- *-----------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <errno.h>
- #include <ctype.h>
- #include <sys/types.h>
- #include <time.h>
- #include <string.h>
-
- #define FALSE 0
- #define TRUE 1
-
- static char cbuff[256], format[80] = "", rev[20] = "";
- static char filename[128], foundRev[20];
- static int year, month, day, hour, minute, second;
- static time_t ltime, ntime;
- static int months[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- static int intfmt, R_opt = FALSE;
-
- main (argc, argv)
- int argc;
- char *argv[];
- {
- register int i, j, k;
- register char *c;
- register struct tm *tmptr;
- FILE *fp;
- char thisRev[20];
-
- intfmt = FALSE;
-
- for (i = 1; i < argc; i++) {
-
- if (*argv[i] == '+') {
-
- for (j = 0, c = &argv[i][1]; *c; c++) {
- format[j++] = '%';
- format[j++] = *c;
- }
-
- } else if (*argv[i] == '-') {
-
- switch (argv[i][1])
- {
- case 'i':
- intfmt = (intfmt) ? FALSE : TRUE;
- break;
-
- case 'r':
- strcpy (rev, &argv[i][2]);
- break;
-
- case 'R':
- R_opt = TRUE;
- break;
-
- default:
- fprintf (stderr, "rcstime: Unrecognized option %s\n", argv[i]);
- continue;
- }
-
- } else { /* Must be a filename */
-
- if (index (argv[i], '/') == NULL) {
- strcpy (filename, "./RCS/");
- strcat (filename, argv[i]);
- j = strlen (filename) - 2;
- if ((filename[j] != ',') || (filename[j+1] != 'v'))
- strcat (filename, ",v");
- if (access (filename, 4))
- strcpy (filename, argv[i]);
- } else {
- strcpy (filename, argv[i]);
- }
- j = strlen (filename) - 2;
- if ((filename[j] != ',') || (filename[j+1] != 'v'))
- strcat (filename, ",v");
- if (access (filename, 4)) {
- fprintf (stderr, "rcstime: Can't find RCS file %s\n", argv[i]);
- continue;
- }
-
- if ((fp = fopen (filename, "r")) == NULL) {
- fprintf (stderr, "rcstime: Something wrong with opening the");
- fprintf (stderr, " RCS file. Major problem = %d\n",
- errno);
- exit (1);
- }
-
- /*----
- * Search for desired revision number or, if none given,
- * search all revisions.
- *----*/
-
- k = strlen (rev);
- ntime = 0;
- foundRev[0] = '\0';
- while (fgets (cbuff, 256, fp)) {
- if (strncmp (cbuff, "desc", 4) == 0) {
- if (ntime == 0)
- {
- fprintf (stderr,
- "rcstime: Can't find requested revision %s in file %s\n",
- rev, argv[i]);
- break;
- }
-
- if (intfmt) {
- if (R_opt)
- printf ("%s ", foundRev);
- printf ("%d\n", ntime);
- } else if (format[0] == '\0') {
- if (R_opt)
- printf ("%s ", foundRev);
- c = ctime (&ntime);
- printf ("%s", c);
- } else {
- if (R_opt)
- printf ("%s ", foundRev);
- cftime (cbuff, format, &ntime);
- printf ("%s\n", cbuff);
- }
-
- break;
- }
-
- j = strlen (cbuff) - 1;
- cbuff[j] = '\0';
- if ( ! isdigit (cbuff[0]))
- continue;
- if ((k == 0) ||
- ((k != 0) && (strncmp (cbuff, rev, k) == 0))) {
-
- strcpy (thisRev, cbuff);
- fgets (cbuff, 256, fp);
- if (strncmp (cbuff, "date", 4) != 0) {
- fprintf (stderr,
- "rcstime: Improperly formatted RCS file %s\n",
- argv[i]);
- break;
- }
-
- tzset ();
- sscanf (cbuff, "%*s %2d.%2d.%2d.%2d.%2d.%2d;", &year,
- &month, &day, &hour, &minute, &second);
- ltime = year - 70;
- ltime = (ltime * 365) +
- ((ltime + ((month > 2) ? 2 : 1)) / 4);
- month--;
- for (j = 0; j < month; j++)
- ltime += months[j];
- ltime += day - 1;
- ltime = (ltime * 24) + hour;
- ltime = (ltime * 60) + minute;
- ltime = (ltime * 60) + second + timezone;
-
- if (ltime > ntime)
- {
- ntime = ltime;
- strcpy (foundRev, thisRev);
- }
- }
- }
-
- fclose (fp);
- }
- }
- }
-